package helper;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: Eugene
 * Date: 12/16/12
 * Time: 6:50 PM
 * To change this template use File | Settings | File Templates.
 */
public class BERCounter {
    /**
     * Calculates BER
     * @param received
     * @param ethalon
     * @return
     */
    public static Double calculateBER(String received, String ethalon) {

        assert (received.length() == ethalon.length());
        Double result;
        int errorCounter = 0;
        int stringsLength = received.length();
        for (int i = 0; i < stringsLength; i++) {
            if (received.charAt(i) != ethalon.charAt(i)) {
                errorCounter += 1;
            }
        }
        result=(double) errorCounter/stringsLength;
        return result;
    }

    /**
     * Calculates BER
     * @param received
     * @param ethalon
     * @return
     */
    public static Double calculateBER  (List<Boolean> received, List<Boolean> ethalon){
        assert (received.size() == ethalon.size());
        Double result;
        int errorCounter = 0;
        int listLength = received.size();
        for (int i = 0; i < listLength; i++) {
            if (received.get(i) != ethalon.get(i)) {
                errorCounter += 1;
            }
        }
        result=(double) errorCounter/listLength;
        return result;

    }
}
